home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
zbpc_460.zip
/
UTILITY.EXE
/
CALL1.BAS
< prev
next >
Wrap
BASIC Source File
|
1990-06-16
|
2KB
|
39 lines
00010 ' This program demonstrates a method by which BASICA's CALL statement
00020 ' can be emulated (with parameter passing)
00030 :
00040 DIM Offset%,Segment% : ' Segment% MUST come directly after Offset%
00050 :
00060 LONG FN Call_A(Offset%,Segment%,PARM1%,PARM2%,DEST%) : 'etc...
00070 ' Each parameter must be pushed on the stack
00080 MACHLG &B8, PARM1% : ' MOV AX,PARM1%
00090 MACHLG &50 : ' PUSH AX
00100 MACHLG &B8, PARM2% : ' MOV AX,PARM2%
00110 MACHLG &50 : ' PUSH AX
00120 MACHLG &8B, &06, DEST% : ' MOV AX,[DEST%]
00130 MACHLG &50 : ' PUSH AX
00140 ' And then a FAR CALL must be performed to the subroutine
00150 MACHLG &FF, &1E, Offset% : ' CALL [Offset%] ; intersegment call
00160 END FN
00170 :
00180 ' First, get the two numbers to add
00190 INPUT "Enter two integers to add together (A%,B%) -> "; A%, B%
00200 ' And then call the LONG FN to perform the actual CALL
00210 FN Call_A(LINE 290, MEMC, A%, B%, VARPTR(C%)) : ' Add 'em together
00220 PRINT C% : ' Print the stored result
00230 END
00240 :
00250 ' This machine language subroutine simply adds two variables and stores
00260 ' the result in a third. Addresses for all three variables are passed
00270 ' on the stack.
00280 :
00290 MACHLG &55 : ' PUSH BP ; Save BP
00300 MACHLG &89, &E5 : ' MOV BP,SP ; Get frame pointer
00310 MACHLG &8B,&76,&0A : ' MOV SI,[BP+10] ; Get address of first parm
00320 MACHLG &8B,&04 : ' MOV AX,[SI] ; Get value of first parm
00330 MACHLG &8B,&76,&08 : ' MOV SI,[BP+8] ; Get address of parm 2
00340 MACHLG &03,&04 : ' ADD AX,[SI] ; Add value to parm 1
00350 MACHLG &8B,&7E,&06 : ' MOV DI,[BP+6] ; Get address for result
00360 MACHLG &89,&05 : ' MOV [DI],AX ; Store result of addition
00370 MACHLG &5D : ' POP BP ; Restore BP
00380 MACHLG &CA,&06,&00 : ' RETF 6 ; Far return, pop parms from stack